//
//  UIViewExtension.swift
//  LongLian369
//
//  Created by 杨蒙 on 16/7/3.
//  Copyright © 2016年 北京龙链科技有限公司. All rights reserved.
//

import UIKit

// MARK: 屏幕的宽高
let JKscreenW: CGFloat = UIScreen.main.bounds.width
let JKscreenH: CGFloat = UIScreen.main.bounds.height

// MARK: 宽高的判断
/// iPhone 5
//let isIPhone5 = JKscreenH == 568 ? true : false
///// iPhone 6
//let isIPhone6 = JKscreenH == 667 ? true : false
///// iPhone 6P
//let isIPhone6P = JKscreenH == 736 ? true : false

// MARK: 关于UIView的x，y,width,height的判断
extension UIView {
    
    /**
        裁剪 view 的圆角
     */
    func clipRectCorner(direction: UIRectCorner, cornerRadius: CGFloat) {
        let cornerSize = CGSize(width:cornerRadius, height:cornerRadius)
        let maskPath = UIBezierPath(roundedRect: bounds, byRoundingCorners: direction, cornerRadii: cornerSize)
        let maskLayer = CAShapeLayer()
        maskLayer.frame = bounds
        maskLayer.path = maskPath.cgPath
        layer.addSublayer(maskLayer)
        layer.mask = maskLayer
    }
    
    /**
       x的位置
     */
    var x: CGFloat {
        get {
            return frame.origin.x
        }
        set(newValue) {
            var tempFrame: CGRect = frame
            tempFrame.origin.x    = newValue
            frame                 = tempFrame
        }
    }
    
    /**
        y的位置
     */
    var y: CGFloat {
        get {
            return frame.origin.y
        }
        set(newValue) {
            var tempFrame: CGRect = frame
            tempFrame.origin.y    = newValue
            frame                 = tempFrame
        }
    }

    /**
       height: 视图的高度
     */
    var height: CGFloat {
        get {
            return frame.size.height
        }
        set(newValue) {
            var tempFrame: CGRect = frame
            tempFrame.size.height = newValue
            frame                 = tempFrame
        }
    }
    
    /**
        width: 视图的宽度
     */
    var width: CGFloat {
        get {
            return frame.size.width
        }
        set(newValue) {
            var tempFrame: CGRect = frame
            tempFrame.size.width = newValue
            frame = tempFrame
        }
    }
    
    /**
       size: 视图的zize
     */
    var size: CGSize {
        get {
            return frame.size
        }
        set(newValue) {
            var tempFrame: CGRect = frame
            tempFrame.size = newValue
            frame = tempFrame
        }
    }
    
    /**
       centerX: 视图的X中间位置
     */
    var centerX: CGFloat {
        get {
            return center.x
        }
        set(newValue) {
            var tempCenter: CGPoint = center
            tempCenter.x = newValue
            center = tempCenter
        }
    }
    
    /**
        centerY: 视图Y的中间位置
     */
    var centerY: CGFloat {
        get {
            return center.y
        }
        set(newValue) {
            var tempCenter: CGPoint = center
            tempCenter.y = newValue
            center = tempCenter;
        }
    }
    
}



